<%@page import="com.alex.common.security.SimpleAuthor"%>
<%@page import="com.alex.common.tools.HostUtils"%>
<%@page import="com.alex.common.cache.CommonCacheManager"%>
<%@page language="java" pageEncoding="UTF-8"%>
<%
	SimpleAuthor.getInstance().needAdmin(request, response);
%>
<html>
<head>
<title>Show System Infomation</title>

<script src="/static/assets/js/jquery-1.9.0.min.js"
	type="text/javascript"></script>

<!-- um begin -->
<link href="/static/um/themes/default/css/umeditor.min.css"
	type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8"
	src="/static/um/umeditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
	src="/static/um/umeditor.min.js"></script>
<script type="text/javascript" src="/static/um/lang/zh-cn/zh-cn.js"></script>
<!-- um over -->

<script type="text/javascript">
	function insertHtml() {
		var value = prompt('插入html代码', '');
		ue.execCommand('insertHtml', value);
	}

	function getAllHtml() {
		alert(UM.getEditor('editor').getAllHtml());
	}

	function getContent() {
		var arr = [];
		arr.push("使用editor.getContent()方法可以获得编辑器的内容");
		arr.push("内容为：");
		arr.push(UM.getEditor('editor').getContent());
		alert(arr.join("\n"));
	}
	function isFocus() {
		alert(ue.isFocus());
	}
	function doBlur() {
		ue.blur();
	}
	function getPlainTxt() {
		var arr = [];
		arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
		arr.push("内容为：");
		arr.push(UM.getEditor('editor').getPlainTxt());
		alert(arr.join('\n'));
	}
	function setContent(isAppendTo) {
		var arr = [];
		arr.push("使用editor.setContent('欢迎使用umeditor', true)方法可以设置编辑器的内容");
		UM.getEditor('editor').setContent('欢迎使用umeditor', isAppendTo);
		alert(arr.join("\n"));
	}
	function setDisabled() {
		UM.getEditor('editor').setDisabled('fullscreen');
		disableBtn("enable");
	}

	function setEnabled() {
		UM.getEditor('editor').setEnabled();
		enableBtn();
	}

	function getText() {
		// 当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
		var range = UM.getEditor('editor').selection.getRange();
		range.select();
		var txt = UM.getEditor('editor').selection.getText();
		alert(txt);
	}

	function getContentTxt() {
		var arr = [];
		arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
		arr.push("编辑器的纯文本内容为：");
		arr.push(UM.getEditor('editor').getContentTxt());
		alert(arr.join("\n"));
	}
	function hasContent() {
		var arr = [];
		arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
		arr.push("判断结果为：");
		arr.push(UM.getEditor('editor').hasContents());
		alert(arr.join("\n"));
	}
	function setFocus() {
		UM.getEditor('editor').focus();
	}
	function deleteEditor() {
		disableBtn();
		UM.getEditor('editor').destroy();
	}
	function disableBtn(str) {
		var div = document.getElementById('btnContainer');
		var btns = UM.dom.domUtils.getElementsByTagName(div, "button");
		for ( var i = 0, btn; btn = btns[i++];) {
			if (btn.id == str) {
				UM.dom.domUtils.removeAttributes(btn, [ "disabled" ]);
			} else {
				$(btn).attr("disabled", true).addClass("disabled");
			}
		}
	}
	function enableBtn() {
		var div = document.getElementById('btnContainer');
		var btns = UM.dom.domUtils.getElementsByTagName(div, "button");
		for ( var i = 0, btn; btn = btns[i++];) {
			$(btn).removeAttr("disabled").removeClass("disabled");
		}
	}
</script>

</head>
<body>
	<h1>Hello, System</h1>
	ClientSign:
	<%=HostUtils.getClientSign(request)%>
	<br />
	<br />RealPath:
	<%=application.getRealPath("/")%>
	<br />
	<br />ServerInfo:
	<%=application.getServerInfo()%>
	<br />
	<br />LocalAddr:
	<%=request.getLocalAddr()%>
	<br />
	<br />RemoteAddr:
	<%=request.getRemoteAddr()%>
	<br />
	<br />X-Forwarded-For:
	<%=request.getHeader("X-Forwarded-For")%>
	<br />
	<br />X-Real-IP:
	<%=request.getHeader("X-Real-IP")%>
	<br />
	<br /> RemoteAddr:
	<%=request.getRemoteAddr()%>
	<br />
	<br /> RemoteHost:
	<%=request.getRemoteHost()%>
	<br />
	<br /> X-Real-Host:
	<%=request.getHeader("X-Real-Host")%>
	<br />
	<br />VCAP_SERVICES:
	<%=System.getenv("VCAP_SERVICES")%>
	<br />
	<pre>
	MySQL is here:
	...
	Cache is here:
	<%=CommonCacheManager.getInstance().getStats()%>
	</pre>
	<br />

	<div title="Some system tools">
		<a href="/common/query?clazName=SayingPO">SayingPO</a> | <a
			href="/common/query?clazName=com.alex.webnote.domain.WebNotePO">WebNotePO</a>
		| <a href="/sysinfo.jsp">System Information</a> | <a href="/mda">MDA</a>
		| <a href="/hotsworker?name=webnotehots">webnote hots worker</a>
	</div>
	<br />

	<div style="width: 800px; margin: 20px auto 40px;">
		<script type="text/plain" id="editor"
			style="width: 100%; height: 400px;"></script>
	</div>
	<div id="btnContainer" style="width: 800px; margin: 20px auto 40px;">
		<table>
			<tr>
				<td>
					<button unselected="on" onclick="getAllHtml()">获得整个html的内容</button>&nbsp;
					<button onclick="getContent()">获得内容</button>&nbsp;
					<button onclick="setContent()">写入内容</button>&nbsp;
					<button onclick="setContent(true)">追加内容</button>&nbsp;
					<button onclick="getContentTxt()">获得纯文本</button>&nbsp;
					<button onclick="getPlainTxt()">获得带格式的纯文本</button>&nbsp;
					<button onclick="hasContent()">判断是否有内容</button>
				</td>
			</tr>
			<tr>
				<td>
					<button onclick="setFocus()">编辑器获得焦点</button>&nbsp;
					<button onmousedown="isFocus();return false;">编辑器是否获得焦点</button>&nbsp;
					<button onclick="doBlur()">编辑器取消焦点</button>&nbsp;
					<button onclick="insertHtml()">插入给定的内容</button>&nbsp;
					<button id="enable" onclick="setEnabled()">可以编辑</button>&nbsp;
					<button onclick="setDisabled()">不可编辑</button>
				</td>
			</tr>
			<tr>
				<td>
					<button onclick="UM.getEditor('editor').setHide()">隐藏编辑器</button>&nbsp;
					<button onclick="UM.getEditor('editor').setShow()">显示编辑器</button>&nbsp;
				</td>
			</tr>

		</table>
	</div>
	<!--script type="text/javascript" src="/static/um/umine.js"></script-->
	
	<br />

</body>
</html>